<div class="layui-fluid nepadmin-pad0 nepadmin-mar0 list0 pay_set" id="list" lay-title="包机列表">
    <div class="layui-fluid">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-body">

                        <div>
                            <!-- <button class="layui-btn layuiadmin-btn-list" data-type="batchdel">删除</button> -->
                            <button class="layui-btn layuiadmin-btn-list" data-type="add">添加</button>
                        </div>
                        <table class="layui-hide" id="list-table" lay-filter="list-table"></table>
                        <script type="text/html" id="list-tableF">
                            <input type="checkbox" name="status" lay-skin="switch" lay-text="启用|停用" lay-filter="list-tableF"
                                   value="{{ d.status }}" data-json="{{ encodeURIComponent(JSON.stringify(d)) }}" {{ d.status == '1' ? 'checked' : '' }}>
                        </script>
                        <div id="list-toolbar" style="display: none;">

                            <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
                    			  {{#if(d.activity_type == 2){ }}
<!--                                          <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>-->
                                          {{# } }}
                        </div>
                        <script type="text/html" id="grand_total">
                            {{d.grand_total}}{{#if(d.unit == 1){ }}小时{{#  } else{ }}天{{# } }}
                        </script>
                        <script type="text/html" id="type">
                            {{#if(d.type == 1){ }}
                            年
                            {{#  } else if(d.type==2){ }}
                            季
                            {{#  } else if(d.type==3){ }}
                            月
                            {{#  } else if(d.type==4){ }}
                            周
                            {{#  } else if(d.type==5){ }}
                            日
                            {{# } }}
                        </script>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script>
    //表格数据渲染
    var formurl='marketing/charterform',formarea=['500px', '580px'];
    var formurls='marketing/charterform',formarea=['500px', '680px'];
    layui.use(['table','form'], function () {
        var table = layui.table
            ,form = layui.form
            ,$ = layui.$;
        layui.admin.initlist(table,'activity/charter_list',155,[[
            {field:'activity_id', title: 'ID', width:50}
            ,{field:'device_group_name', title: '设备组', width:200}
            ,{field:'activity_name', title: '活动名称', width:150}
            ,{field:'grand_total', title: '时间（天）', width:200,templet:'#grand_total'}
            ,{field:'price', title: '价格', width:100}
            ,{field:'detail', title: '说明', minWidth:200}
            ,{field:'status', title:'启用/停用', width:100, templet: '#list-tableF', unresize: true}
            /* ,{field:'create_time', title: '创建时间', width:200} */
            ,{title:'操作', toolbar: '#list-toolbar',fixed:'right', width:200}
        ]])
        //监听表格表单操作
        form.on('switch(list-tableF)', function(obj){
            var json = JSON.parse(decodeURIComponent($(this).data('json')));
            json = table.clearCacheKey(json);
            layui.admin.ajax('activity/update',{
                status:json.status==1?2:1,
                activity_id:json.activity_id
            }).then(function(res){
                table.reload('list-table');
            }).catch(function(res){});
        });

        //监听表格操作事件
        table.on('tool(list-table)', function(obj){
            var data = obj.data;
            //删除
            if(obj.event === 'del'){
                layer.confirm('确定删除'+data.activity_name+'?', function(index){
                    layui.admin.delF(table,'activity/delete',{activity_id:data.activity_id});
                });
            } else if(obj.event === 'edit'){//编辑
                layui.admin.pupF('编辑活动',formarea,formurl,2,data)
            }
        });
        //监听行双击事件
        /* table.on('rowDouble(list-table)', function(obj){
            //查看详情
            if($('.pay_set').length){
                layui.admin.pupF('支付详情',formarea,formurl,3,obj.data);
            }

        }); */
        var active = {
            //多行删除
            batchdel:function(){
                layui.admin.delsF(table,'payment/pay_type_delete','pay_type_id')
            }
            //添加
            ,add: function(othis){
                layui.admin.pupF('添加活动',formarea,formurls,1,{})
            }
        };
        //操作dom
        $('.layui-btn.layuiadmin-btn-list').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

    });
</script>